package stark.app.function.news;

import android.content.Context;
import android.content.Intent;
import android.webkit.WebView;

import androidx.annotation.Nullable;
import androidx.core.text.HtmlCompat;
import stark.app.R;
import stark.app.databinding.ActivityNewsDetailBinding;
import stark.common.apis.ApiManager;
import stark.common.apis.base.NewsBean;
import stark.common.base.IReqRetCallback;
import stark.common.basic.base.BaseNoModelActivity;
import stark.common.basic.constant.Extra;
import stark.common.basic.utils.IntentUtil;

/**
 * Author：daizhongbin on 2022/12/1
 * Email：1027154338@qq.com
 * Desc:
 */
public class NewsDetailActivity extends BaseNoModelActivity<ActivityNewsDetailBinding> {

    public static void start(Context context, NewsBean newsBean) {
        Intent intent = IntentUtil.getIntent(context, NewsDetailActivity.class);
        intent.putExtra(Extra.DATA, newsBean);
        context.startActivity(intent);
    }

    @Override
    protected int onCreate() {
        return R.layout.activity_news_detail;
    }

    @Override
    protected void initView() {
        Intent intent = getIntent();
        NewsBean newsBean = (NewsBean) intent.getSerializableExtra(Extra.DATA);
        if (newsBean == null) {
            return;
        }

        mDataBinding.tvTitle.setText(newsBean.title);
        mDataBinding.tvAuthor.setText("来源：" + newsBean.author_name);
        ApiManager.newsApi().getNewsDetail(this, newsBean.uniquekey, new IReqRetCallback<NewsBean>() {
            @Override
            public void onResult(boolean success, String msg, @Nullable NewsBean result) {
                if (result != null) {
                    mDataBinding.webView.loadData(result.content, null, null);
                }
            }
        });
    }

    @Override
    protected void initData() {

    }
}
